package com.lin.controller;


import com.lin.commons.Result;
import com.lin.entity.CompInformation;
import com.lin.service.CompInformationService;
import com.lin.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 林伟鸿
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/compInformation")
@CrossOrigin
public class CompInformationController {

    @Autowired
    CompInformationService compInformationService;

    @GetMapping("/allCompInfo")
    public DataVO<CompInformation> getAllCompInfo(Integer page, Integer limit, String userId) {
        return compInformationService.getUserCompInfo(page, limit, Integer.parseInt(userId));
    }


    @PostMapping("/compensate")
    public Result compensate(@RequestParam String userId, @RequestParam String orderSerial) {
        int compensate = compInformationService.compensate(orderSerial, userId);
        if (compensate == 1) {
            return Result.success("理赔成功，订单结束");
        } else {
            return Result.failure("理赔失败，请重新尝试");
        }
    }
}

